<?php
namespace app\api\controller\zfshop;
class Shareshop extends Base
{

    public function __construct() {
        parent::__construct();
    }

    //  店铺详情 根据用户ID查询
    public function detailsId(){
        $d = $this->post();
        $rule = [
            'user_id'=>'require'
        ];
        $msg = [];
        check($rule,$msg,$d);
        $info = $this->db->query("select id as shop_id,username,pic,introduce from user_ext where user_id=? and status=0",[$d["user_id"]],1);
        $info['invitecode'] = en_id($d["user_id"]);
        return suc($info);
    }

    public function goodsLists(){
        $d = $this->post();
        $rule = [
            'page'=>'require|integer',
            'limit'=>'require|integer',
            'shop_id'=>'require'
        ];
        $msg = [
        ];
        check($rule,$msg,$d);

        $map = [];
        $map[] = ["and","a.user_ext_id","=",$d["shop_id"]];
        $w = where($map);
        $order = "order by a.id desc";
        $sql = "
            select
                b.id as goods_id,
                b.goods_price_id as goods_price_id,
                b.title goods_name,
                b.pic,
                b.price,
                b.point,
                b.sales_volume,
                b.gulijin_money,
                a.id as goods_agent_id,
                a.create_time
            from
                goods_agent a
            inner join
                goods b on b.id = a.goods_id
        $w[0] {$order} ".limit($d['page'],$d['limit']);
        $rs = $this->db->query($sql,$w[1],'',true);
        foreach ($rs[0] as $k => $v) {
            $rs[0][$k]["create_time_name"] = com_time_format($v['create_time'],'Y-m-d');
        }
        suc($rs[0],$rs[1]);
    }

}
